'''
用for循环和while来完成简单的计数

用for循环和while循环两种方式来实现斐波那契函数, 限制在100以内

斐波那契函数

第N项是N-1, N-2的和

F(n)=F(n - 1)+F(n - 2)

[0, 1, 1, 2, 3, 5, 8, 13, 21....]
在第二周-第一节课我们实现的简单计算器的基础上, 对参数进行检查, 如果报错就抛出我们自定义异常ParamsError
'''
# 用for循环和while来完成简单的计数
l = [1,3,5,4,9,7]
count = 0
print("==================for=============")
for i in l:
    count += 1
    print("现在是第"+ str(count) +"个数，其值为：", i)

print("==================for=============")
for i,e in enumerate(l):
    print(f"现在的排名为: {i+1}, 分数是：{e}")
print("==================while=============")
i = 0
while i<= len(l):
    i += 1
    print("现在是第"+ str(i) +"个数，其值为：", i)
print("==================break=============")
i = 0
while True:
    i += 1
    if i > len(l)+1:
        break
    print("现在是第" + str(i) + "个数，其值为：", i)

# 用for循环和while循环两种方式来实现斐波那契函数, 限制在100以内
print("==============for实现斐波那契函数=============")
a = 0
b = 1
fn = 0
for i in range(2,100):
    fn = a + b
    a = b
    b = fn
    if fn > 100:
        break
    print(fn, end=" ")
print("\n")
print("==============while实现斐波那契函数=============")
a = 0
b = 1
fn = 0
while fn <= 100:
    fn = a + b
    a = b
    b = fn
    if fn > 100:
        break
    print(fn, end=" ")
print("\n")

# 自定义异常ParamsError
class ParamsError(Exception):
    raise print("参数出错啦？")
def add(a,b):
    return a + b ;
def sub(a,b):
    return a - b;
def mul(a,b):
    return a * b;
def div(a,b):
    try:
        return a / b
    except ParamsError :
        return None
def rem(a,b):
    return a // b;
def ediv(a,b):
    return a % b;
def sqrt(a):
    c = int(a)
    if c>=0:
        return c ** (1/2);
    else:
        return "开方数不能小于零？";
c = input("请输入你的运算符号：‘加法：+、减法：-、乘法：*、除法：/，整除：//，取余：%，开方：%%：")
# input3 = input("请输入你要开方的数，如果不是进行开方运算请按回车键")

if c == '%%':
    a = float(input("请输入你要开方的数:"))
    print(a,"^(1/2)","=",sqrt(a))
else:
    a = float(input("请输入你要运算的第一个数："))
    b = float(input("请输入你要运算的第二个数："))
    # c = input("请输入你的运算符号：‘+、-、*、/，//，%，开方：%%")
    if c == '+':
        print(a,"+",b,"=",add(a,b))
    elif c == '-':
        print(a,"-",b,"=",sub(a,b))
    elif c == '*':
        print(a,"*",b,"=",mul(a,b))
    elif c == '-':
        print(a,"/",b,"=",div(a,b))
    elif c == '-':
        print(a,"//",b,"=",ediv(a,b))
    elif c == '-':
        print(a,"%",b,"=",rem(a,b))
    elif c == '-':
        print(a,"^(1/2)",b,"=",sqrt(a,b))
    else :
        print("请输入正确的运算？")